﻿﻿@using System.ComponentModel

<MudTable  @ref="_filteredTable" Items="_states" Filter="new Func<string, bool>(FilterFunc)">
    <ToolBarContent>
        <MudText>Filtered Item Count: @FilteredItemCount</MudText>
        <MudSpacer />
        <MudTextField id="searchString"  @bind-Value="_searchString" Placeholder="Search"></MudTextField>
    </ToolBarContent>
    <RowTemplate>
        <MudTd>@context</MudTd>
    </RowTemplate>
    <PagerContent>
        <MudTablePager />
    </PagerContent>
</MudTable>

@code {
    public static string __description__ = "Info in pager should show '0-0 of 0' when filter did not match anything";

    private string? _searchString;
    private MudTable<string> _filteredTable = null!;

    private readonly string[] _states =
    [
        "Alabama", "Alaska", "American Samoa", "Arizona",
        "Arkansas", "California", "Colorado", "Connecticut",
        "Delaware", "District of Columbia", "Federated States of Micronesia",
        "Florida", "Georgia", "Guam", "Hawaii", "Idaho",
        "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky",
        "Louisiana", "Maine", "Marshall Islands", "Maryland",
        "Massachusetts", "Michigan", "Minnesota", "Mississippi",
        "Missouri", "Montana", "Nebraska", "Nevada",
        "New Hampshire", "New Jersey", "New Mexico", "New York",
        "North Carolina", "North Dakota", "Northern Mariana Islands", "Ohio",
        "Oklahoma", "Oregon", "Palau", "Pennsylvania", "Puerto Rico",
        "Rhode Island", "South Carolina", "South Dakota", "Tennessee",
        "Texas", "Utah", "Vermont", "Virgin Island", "Virginia",
        "Washington", "West Virginia", "Wisconsin", "Wyoming"
    ];

    private string FilteredItemCount => _filteredTable.GetFilteredItemsCount().ToString();

    private bool FilterFunc(string state)
    {
        if (string.IsNullOrWhiteSpace(_searchString))
            return true;
        if (state.Contains(_searchString, StringComparison.OrdinalIgnoreCase))
            return true;
        return false;
    }
}